<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ include file="/commons/pages/taglibs.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>${naviString}</title>
<link href="${ctx}/commons/styles/themes/blue/styles/style.css" rel="stylesheet" type="text/css" />
<link href="${ctx}/commons/scripts/jquery-ui/themes/redmond/jquery-ui.custom.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.s-mod-set-view{
    background-image: url("${ctx}/commons/styles/images/spis_4701ebf9.png");
    background-repeat: no-repeat;
    outline: medium none;
}

.s-mod-set-view {
    -moz-user-select: none;
    cursor: pointer;
    height: 20px;
    margin-bottom:-5px;
    width: 22px;
}
.s-mod-set-view {
    background-position: -46px -137px;
}
.s-mod-set-view:hover {
    background-position: -46px -172px;
}
.span_type {
	width: 100px;
	line-height:20px;
	font-size: 12px;
	border:1px solid #E5E5E5;
	display: inline-block;
	overflow: hidden;
}
.span_type:hover{
	border-color:#DDE9F4;
}
.nav-close {
	display: inline-block;
    outline: medium none;
    background-image: url("${ctx}/commons/styles/images/menu_bg_211471e2.png");
    background-repeat: no-repeat;
    float: right;
    margin-right: 5px;
    width: 12px;
    height: 16px;
    margin-top: 3px;
}
.nav-close {
	background-position: -69px -74px;
}
.nav-close:hover {
 	background-position: -69px -92px;
}
-->
</style>
</head>
<body>
<div align="center">
  <div align="center" style="width: 99%">
    <div align="left" class="nav">${naviString}</div>
    <fieldset>
    <legend>快速搜索</legend>
    <html-el:form action="/manager/ProjectExample.do">
      <html-el:hidden property="method" value="list" />
      <html-el:hidden property="mod_id" />
     工程名称：
      <html-el:text property="proj_name_like" />
      &nbsp;
      工程类别：
      <html-el:select property="project_type" styleId="project_type">
      	<html-el:option value="">请选择...</html-el:option>
      	<c:forEach var="pe_cur" items="${peTypeList}">
      	  <html-el:option value="${pe_cur.dictionary_value}">${pe_cur.dictionary_desc_cn}</html-el:option>
      	</c:forEach>
      </html-el:select>
      <span style="cursor:default;">
  		<a class="s-mod-set-view" title="编辑" onclick="config_type()" href="javascript:void(0);" style="display: inline-block;"></a>
  	  </span>
      &nbsp;
      是否已删除:
      <html-el:select property="is_del">
        <html-el:option value="0">未删除</html-el:option>
        <html-el:option value="1">已删除</html-el:option>
      </html-el:select>
      &nbsp;
      <html-el:submit value="快速搜索" styleClass="ui-state-default ui-corner-all" style="cursor:pointer;" />
    </html-el:form>
    </fieldset>
    <fieldset id="con_type" style="margin-right:900px;width:460px;display:none;">
      <span id="hide_add" class="span_type" style="display:none;">
        <input type="text" id="type_name" name="type_name" onkeypress="saveType(this)" style="width:75px;border:none;" value="按回车保存" onmousedown="clearText(this)" /><a class="nav-close" title="删除" style="cursor: pointer;"></a>
      </span>
      <legend>编辑工程类别</legend>
      <c:if test="${empty peTypeList}">
        <span style="float: right;width: 25px;"><img id="add_but" src="${ctx}/commons/styles/images/add_but.png" style="cursor: pointer;" title="添加" /></span>
      </c:if>
      <c:forEach var="pt" items="${peTypeList}" varStatus="vs">
        <span class="span_type">${pt.dictionary_desc_cn}<a lang="${pt.dictionary_value}" class="nav-close" title="删除" style="cursor: pointer;"></a></span>
      	<c:if test="${fn:length(peTypeList) >= 4 && vs.count eq 4 || fn:length(peTypeList) < 4 && vs.last}">
      	  <span style="float: right;width: 25px;"><img id="add_but" src="${ctx}/commons/styles/images/add_but.png" style="margin-top: 3px;cursor: pointer;" title="添加" /></span>
      	</c:if>
      </c:forEach>
    </fieldset>
    <%@ include file="/commons/pages/messages.jsp" %>
    <br/>
    <form id="listForm" name="listForm" method="post" action="ProjectExample.do?method=delete">
      <div style="text-align: left">
        <input type="button" name="delete" id="delete" value="删除所选" onclick="this.form.action += '&' + $('#bottomPageForm').serialize();confirmDeleteAll(this.form);" class="ui-state-default ui-corner-all" style="cursor:pointer;" />
        <input type="button" name="add" id="add" value="添加" onclick="location.href='ProjectExample.do?method=add&mod_id=${hf.map.mod_id}';" class="ui-state-default ui-corner-all" style="cursor:pointer;" />
        <input type="hidden" name="method" id="method" value="delete" />
        <input type="hidden" name="mod_id" id="mod_id" value="${hf.map.mod_id}" />
      </div>
      <br/>
      <table width="100%" border="0" cellpadding="0" cellspacing="1" class="datagrid">
        <tr>
          <th width="5%" nowrap="nowrap"><input name="chkAll" type="checkbox" id="chkAll" value="-1" onclick="checkAll(this);" /></th>
          <th nowrap="nowrap">工程名称</th>
          <th width="15%" nowrap="nowrap">工程类别</th>
          <th width="15%" nowrap="nowrap">添加时间</th>
          <th width="8%" nowrap="nowrap">排序值</th>
          <th width="5%" nowrap="nowrap">改</th>
          <th width="5%" nowrap="nowrap">删</th>
        </tr>
        <c:forEach var="cur" items="${entityList}" varStatus="vs">
          <tr>
            <td align="center"><c:if test="${cur.is_del eq 0}"><input name="pks" type="checkbox" id="pks" value="${cur.project_id}" /></c:if>
              <c:if test="${cur.is_del eq 1}"><input name="pks" type="checkbox" id="pks" value="${cur.project_id}" disabled="disabled" /></c:if></td>
            <td align="left"><a href="ProjectExample.do?method=view&mod_id=${hf.map.mod_id}&project_id=${cur.project_id}">${cur.project_name}</a></td>
            <td align="center"><c:forEach var="p_cur" items="${peTypeList}">
	      	  <c:if test="${p_cur.dictionary_value eq cur.project_type}">${p_cur.dictionary_desc_cn}</c:if>
	      	</c:forEach></td>
	      	<td align="center"><fmt:formatDate value="${cur.add_time}" pattern="yyyy-MM-dd" /></td>
            <td align="center">${cur.order_value}</td>
            <td align="center"><c:if test="${cur.is_del eq 0}"><span style="cursor:pointer;" onclick="confirmUpdate(null, 'ProjectExample.do', 'project_id=${cur.project_id}&' + $('#bottomPageForm').serialize())">改</span></c:if>
              <c:if test="${cur.is_del eq 1}"><span style="color: #ccc">改</span></c:if>
            </td>
            <td align="center"><c:if test="${cur.is_del eq 0}"><span style="cursor:pointer;" onclick="confirmDelete(null, 'ProjectExample.do', 'project_id=${cur.project_id}&' + $('#bottomPageForm').serialize())">删</span></c:if>
              <c:if test="${cur.is_del eq 1}"><span style="color: #ccc">删</span></c:if>
            </td>
          </tr>
        </c:forEach>
      </table>
    </form>
    <form id="bottomPageForm" name="bottomPageForm" method="post" action="ProjectExample.do">
      <table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td height="40" align="center"><script type="text/javascript" src="${ctx}/commons/scripts/pager.js">;</script>
            <script type="text/javascript">
            var pager = new Pager(document.bottomPageForm, ${hf.map.pager.recordCount}, ${hf.map.pager.pageSize}, ${hf.map.pager.currentPage});
            pager.addHiddenInputs("method", "list");
            pager.addHiddenInputs("mod_id", "${hf.map.mod_id}");
            pager.addHiddenInputs("project_name", "${fn:escapeXml(hf.map.project_name)}");
            pager.addHiddenInputs("project_type", "${fn:escapeXml(hf.map.project_type)}");
            pager.addHiddenInputs("is_del", "${hf.map.is_del}");
            document.write(pager.toString());
            </script>
          </td>
        </tr>
      </table>
    </form>
  </div>
</div>
<script type="text/javascript" src="${ctx}/commons/scripts/jquery.js"></script>
<script type="text/javascript" src="${ctx}/commons/scripts/jquery-ui/ui/minified/jquery-ui.custom.min.js"></script>
<script type="text/javascript" src="${ctx}/commons/scripts/rowEffect.js"></script>
<script type="text/javascript">//<![CDATA[
$(document).ready(function(){
	$("input[type='submit'],input[type='button']").css("border", "1px solid");
});

function config_type(){
	$("#con_type").toggle("Fold", null, 500, null);
}

$("#add_but").mouseover(function(){
	$(this).attr("src","${ctx}/commons/styles/images/add_but_light.png");
}).mouseout(function(){
	$(this).attr("src","${ctx}/commons/styles/images/add_but.png");
});

//添加操作
$("#add_but").click(function(){
	if($("#type_name:not(:hidden)","#con_type").length > 0){
		alert("请先保存新增的工程类别，再进行添加操作");
		return;
	}
	
	var clonedObj = $("#hide_add").clone().appendTo($("#con_type"));
	$(clonedObj).show();
	$("#type_name",clonedObj).focus().select();

	//添加的文本框注册删除事件
	$(".nav-close",clonedObj).click(function(){
		$(this).parent().remove();
	});
});

//清楚输入框中的默认文本
function clearText(obj){
	if("" == $.trim($(obj).val())) return;
	
	if("按回车保存" == $(obj).val())
		$(obj).val("");
}

//for循环中的删除按钮注册删除事件
$(".nav-close").click(function(){
	deleteProjectType($(this));
});

function deleteProjectType(obj){
	if($(obj).attr("lang") == "" || $(obj).attr("lang") == null) return;

	var succ = false;
	if(confirm("确定删除此项工程类别？")){
		$.ajax({
			async: false,
			type: "POST",
			url: "ProjectExample.do",
			data: "method=deletePeojectType&type_id=" + $(obj).attr("lang"),
			dataType: "json",
			error: function(request, settings) {/*alert("数据请求失败！"); */},
			success: function(data) {
				if(data == -1){
					alert("删除工程类别失败，请重新操作");
				}else {
					succ = true;
				}
			}
		});
	}

	if(succ){
		$(obj).parent().remove();
		//删除工程案例下拉框中对应的option
		$("#project_type option[value='" + $(obj).attr("lang") + "']").remove();   
	}
}

function saveType(obj){
	if($.trim($(obj).val() == "")) return;

	var succ = false;
	var id = "";
	if (event.keyCode==13) {
		if(confirm("确定保存此项工程类别？")){
			$.ajax({
				async: false,
				type: "POST",
				url: "ProjectExample.do",
				data: "method=savePeojectType&type_name=" + $(obj).val(),
				dataType: "json",
				error: function(request, settings) {/*alert("数据请求失败！"); */},
				success: function(data) {
					if(data == -1){
						alert("新增工程类别失败，请重新操作");
					}else {
						id = data;
						succ = true;
					}
				}
			});
		} 
	}  

	if(succ){
		var type_name = $(obj).val();
		var span = $(obj).parent();
		var dele = $(obj).next();
		//输入框消失，转换为文本显示
		$(obj).remove(); 
		$(span).append(type_name);

		if(id != "" && id != -1){ //id为新增的dictionary_value
			$("#project_type").append("<option value='" + id +"'>" + type_name + "</option>");
		}

		$(dele).unbind("click").attr("lang",id);//取消删除按钮原先注册的删除事件
		$(dele).click(function(){ //重新注册为ajax删除
			deleteProjectType($(this));
		});
	}
		
}
//]]></script>
</body>
</html>
